<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | 王勇程 <laughskydragon@qq.com>                         |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\validate;

/**
 * 商品分类验证器
 */
class Category extends ValidateBase
{
    // 验证规则
    protected $rule = [
        'name'          => 'require|length:1,100',
        'parent_id'     => 'integer|egt:0',
        'path'          => 'max:500',
        'level'         => 'integer|between:1,10',
        'sort'          => 'integer|egt:0',
        'icon'          => 'max:50',
        'description'   => 'max:1000',
        'status'        => 'in:0,1',
    ];

    // 验证提示
    protected $message = [
        'name.require'          => '分类名称不能为空',
        'name.length'           => '分类名称长度为1-100个字符',
        'parent_id.integer'     => '父分类ID必须为整数',
        'parent_id.egt'         => '父分类ID不能为负数',
        'path.max'              => '分类路径不能超过500个字符',
        'level.integer'         => '分类层级必须为整数',
        'level.between'         => '分类层级必须在1-10之间',
        'sort.integer'          => '排序权重必须为整数',
        'sort.egt'              => '排序权重不能为负数',
        'icon.max'              => '分类图标不能超过50个字符',
        'description.max'       => '分类描述不能超过1000个字符',
        'status.in'             => '状态值只能为0或1',
    ];

    // 应用场景
    protected $scene = [
        'add'    => ['name', 'parent_id', 'sort', 'icon', 'description', 'status'],
        'edit'   => ['name', 'parent_id', 'sort', 'icon', 'description', 'status'],
    ];
}